/*
 * Copyright 2013-2019 Xia Jun(3979434@qq.com).
 *
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 *      http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 *
 ***************************************************************************************
 *                                                                                     *
 *                        Website : http://www.farsunset.com                           *
 *                                                                                     *
 ***************************************************************************************
 */
package com.workcell.workdata.im.mvc.controller.explore;

import com.workcell.workdata.im.annotation.UID;
import com.workcell.workdata.im.constant.Common;
import com.workcell.workdata.im.entity.EmoticonItem;
import com.workcell.workdata.im.model.response.PaginationEntity;
import com.workcell.workdata.im.model.response.ResponseEntity;
import com.workcell.workdata.im.model.vo.EmoticonVO;
import com.workcell.workdata.im.service.EmoticonService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiImplicitParam;
import io.swagger.annotations.ApiOperation;
import org.springframework.data.domain.Page;
import org.springframework.data.domain.PageRequest;
import org.springframework.data.domain.Pageable;
import org.springframework.data.domain.Sort;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;
import java.util.List;

@RestController
@RequestMapping("/emoticon")
@Api(produces = "application/json", tags = "表情包接口" )
public class EmoticonController {

    @Resource
    private EmoticonService emoticonService;

    @ApiOperation(httpMethod = "GET", value = "获取表情包列表")
    @ApiImplicitParam(name = "currentPage", value = "当前页数", paramType = "path", dataTypeClass = Integer.class,example = "0",required = true)
    @GetMapping(value = "/mall/list/{currentPage}")
    public PaginationEntity<EmoticonVO> list(@PathVariable int currentPage) {
        Pageable pageable = PageRequest.of(currentPage, Common.API_PAGE_SIZE, Sort.by(Sort.Order.desc("id")));
        Page<EmoticonVO> page = emoticonService.queryPage(pageable);
        return PaginationEntity.make(page);
    }

    @ApiOperation(httpMethod = "GET", value = "获取表情包详情")
    @ApiImplicitParam(name = "id", value = "表情包ID", paramType = "path", dataTypeClass = Long.class,example = "0",required = true)
    @GetMapping(value = "/{id}")
    public ResponseEntity<EmoticonVO> get(@PathVariable long id) {
        return ResponseEntity.ok(emoticonService.findOne(id));
    }


    @ApiOperation(httpMethod = "POST", value = "添加表情包")
    @ApiImplicitParam(name = "id", value = "表情包ID", paramType = "path", dataTypeClass = Long.class,example = "0",required = true)
    @PostMapping(value = "/{id}")
    public ResponseEntity<Void> add(@UID Long uid, @PathVariable long id) {
        emoticonService.add(uid,id);
        return ResponseEntity.ok();
    }

    @ApiOperation(httpMethod = "POST", value = "禁用表情包")
    @ApiImplicitParam(name = "id", value = "表情包ID", paramType = "path", dataTypeClass = Long.class,example = "0",required = true)
    @PostMapping(value = "/disable/{id}")
    public ResponseEntity<Void> disable(@UID Long uid,@PathVariable long id) {
        emoticonService.disable(uid,id);
        return ResponseEntity.ok();
    }

    @ApiOperation(httpMethod = "POST", value = "启用表情包")
    @ApiImplicitParam(name = "id", value = "表情包ID", paramType = "path", dataTypeClass = Long.class,example = "0",required = true)
    @PostMapping(value = "/enable/{id}")
    public ResponseEntity<Void> enable(@UID Long uid,@PathVariable long id) {
        emoticonService.enable(uid,id);
        return ResponseEntity.ok();
    }

    @ApiOperation(httpMethod = "GET", value = "获取表情列表")
    @ApiImplicitParam(name = "id", value = "表情包ID", paramType = "path", dataTypeClass = Long.class,example = "0",required = true)
    @GetMapping(value = "/item/list/{id}")
    public ResponseEntity<List<EmoticonItem>> list(@PathVariable long id) {
        return ResponseEntity.ok(emoticonService.findItemList(id));
    }

}
